package com.project.handle.travelHandle;

import com.project.handle.RiskHandle;
import com.project.pojo.RiskController;
import com.project.utils.ErrorMessage;
import com.project.vo.TripAccessVO;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
@Order(2)
public class TravelHandleOfCity implements RiskHandle<TripAccessVO> {
    @Override
    public void RiskAssess(TripAccessVO tripAccessVO, List<RiskController> list, List<ErrorMessage> errorMessageList) {
        final int OTHERCITY_WEIGHT=5;
        boolean flag=false;
        for (RiskController riskController : list) {
            String rule = riskController.getRule();
            flag = rule.contains(tripAccessVO.getCity());
            if (flag==true){
                tripAccessVO.setWeight(tripAccessVO.getWeight()+riskController.getWeight());
                break;
            }
        }
        if (flag==false){
            tripAccessVO.setWeight(tripAccessVO.getWeight()+OTHERCITY_WEIGHT);
        }
    }
}
